﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.DAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.DALFactory;

namespace KPIS.GERP.GHRMS.BLL
{
    public class JobSiteAreaBLL : IJobSiteAreaBLL
    {
        private static readonly IJobSiteAreaDAL DAL = DataAccess.CreateJobSiteAreas();
        //private static readonly IJobSiteDAL jobsiteDAL = DataAccess.CreateJobSites();
        //private static readonly IMasAreaDAL areaDAL = DataAccess.CreateMasterAreas();

        private JobSiteAreaInfo jsareaInfo = new JobSiteAreaInfo();
        private JobSiteInfo jobsiteInfo = new JobSiteInfo();
        private MasAreaInfo areaInfo = new MasAreaInfo();

        public IList<JobSiteAreaInfo> ListJobSiteAreas(string Jobsites)
        {
            if (Jobsites.Length > 0)
                jobsiteInfo.Sequence = Int32.Parse(Jobsites);
            jsareaInfo.JobSites = jobsiteInfo;
            return DAL.ListJobSiteAreas(jsareaInfo);
        }
        public IList<JobSiteAreaInfo> ListJobSiteAreasBySequence(int Sequence)
        {
            return DAL.ListJobSiteAreas(new JobSiteAreaInfo(Sequence));
        }
        public DataSet LoadJobSiteAreas(Nullable<int> Sequence, string Jobsites)
        {
            if (Jobsites.Length > 0)
            {
                jobsiteInfo.Sequence = Int32.Parse(Jobsites);
                jsareaInfo.JobSites = jobsiteInfo;
            }
            if (Sequence.HasValue)
                jsareaInfo.Sequence = (int)Sequence;
            else
                jsareaInfo.Sequence = 0;

            return DAL.LoadJobSiteAreas(jsareaInfo);
        }
        public void Insert(string JobSites, string AreaName, string Remarks, int CreatedBy)
        {
            try
            {
                if (JobSites.Length > 0)
                    jobsiteInfo.Sequence = Int32.Parse(JobSites);
 
                DAL.Insert(new JobSiteAreaInfo(0, jobsiteInfo, AreaName, Remarks, "", CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string JobSites, string AreaName, string Remarks, int UpdatedBy)
        {
            try
            {
                if (JobSites.Length > 0)
                    jobsiteInfo.Sequence = Int32.Parse(JobSites);

                DAL.Update(new JobSiteAreaInfo(Sequence, jobsiteInfo, AreaName, Remarks, "", 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, int UpdatedBy)
        {
            try
            {
                DAL.Delete(Sequence, UpdatedBy);
            }
            catch
            {
                throw new Exception("");
            }
        }
        
    }
}
